# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        Young  
# Name:         demo1033
# Description:
# Author:       $赵怡蕾
# Date:         2019/3/27
#-------------------------------------------------------------------------------

class Rectangle:
    def __init__(self):
        self.width = 0
        self.height = 0
        self.left = 0
        self.top = 0

    def __setattr__(self, name, value):
        print("{}被设置,新值为{}".format(name, value))
        if name == 'size':
            self.width, self.height = value
        elif name == 'position':
            self.left, self.top = value
        else:
            # 内部维护的一个特殊属性成员变量,用于保存成员变量的值,所以这条语句必须加上
            self.__dict__[name] = value

    def __getattr__(self, name):
        print("{}被获取".format(name))
        if name == 'size':
            return self.width, self.height
        elif name == 'position':
            return self.left, self.top

    def __delattr__(self, name):
        if name == 'size':
            self.width, self.height = 0, 0
        elif name == 'position':
            self.left, self.top = 0, 0


r = Rectangle()
r.size = 100, 200
r.positon = 300, 400